//
//  DriverOrderCell.m
//  Zhiche-Carriage
//
//  Created by LeeBruce on 16/11/1.
//  Copyright © 2016年 LeeBruce. All rights reserved.
//

#import "DriverOrderCell.h"
#import <Masonry.h>


@implementation DriverOrderCell


-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubViews];
        
    }
    
    return  self;
}

-(void)initSubViews
{
    __weak typeof(self) weakSelf = self;
    
    //时间
    self.timeLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
   
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(200, 40 * kHeight));
    
    }];
    self.timeLabel.font = Font(14);
    self.timeLabel.textColor = Color_RGB(51, 51, 51, 1);
    
    //状态
    
    self.statusLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.statusLabel];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(0);
        make.right.mas_equalTo(-10);
        make.size.mas_equalTo(CGSizeMake(100, 40 * kHeight));

    }];
    self.statusLabel.textAlignment = NSTextAlignmentRight;
    self.statusLabel.textColor = YellowColor;
    self.statusLabel.font = Font(10);
    
    //起始地
    UIImageView *startImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"start"]];
    [self.contentView addSubview:startImg];
    [startImg mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(weakSelf.timeLabel.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(15, 22));
        
    }];
    
    
    UILabel *rowL = [[UILabel alloc]init];
    [self.contentView addSubview:rowL];
    rowL.backgroundColor = LineGrayColor;
    [rowL mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(startImg.mas_right).offset(10);
        make.top.equalTo(startImg);
        make.size.mas_equalTo(CGSizeMake(0.5, 50 ));
        
    }];
    
    self.startAddressLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.startAddressLabel];
    [self.startAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(rowL.mas_right).offset(10);
        make.top.equalTo(rowL);
        make.size.mas_equalTo(CGSizeMake(200, 22));
        
    }];
    self.startAddressLabel.font = Font(12);
    self.startAddressLabel.textColor = AddressSCtitleColor;
    
    
    
    
    //目的地
    UIImageView *endImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"end"]];
    [self.contentView addSubview:endImg];
    [endImg mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(startImg.mas_bottom).offset(8);
        make.size.mas_equalTo(CGSizeMake(15, 22));
        
    }];
    
    self.endAddressLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.endAddressLabel];
    [self.endAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(rowL.mas_right).offset(10);
        make.top.equalTo(endImg);
        make.size.mas_equalTo(CGSizeMake(200, 22));
        
    }];
    self.endAddressLabel.font = Font(12);
    self.endAddressLabel.textColor = AddressSCtitleColor;
    
    //价格
    self.moneyLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.moneyLabel];
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.equalTo(weakSelf.statusLabel);
        make.top.equalTo(startImg);
        make.size.mas_equalTo(CGSizeMake(150, 50));
        
    }];
    
    self.moneyLabel.textAlignment = NSTextAlignmentRight;
    self.moneyLabel.textColor = YellowColor;
    self.moneyLabel.font = Font(17);

    
    UILabel *lineL = [[UILabel alloc]init];
    [self.contentView addSubview:lineL];
    lineL.backgroundColor = LineGrayColor;
    [lineL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(10);
        make.top.equalTo(endImg.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(screenWidth - 10, 0.5 ));
        
    }];

    
    //查看详情
    self.detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.detailButton];
    [self.detailButton setTitle:@"查看详情" forState:UIControlStateNormal];
    self.detailButton.backgroundColor = YellowColor;
    [self.detailButton setTitleColor:WhiteColor forState:UIControlStateNormal];
    [self.detailButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(lineL.mas_bottom).offset(10* kHeight);
        make.size.mas_equalTo(CGSizeMake(100, 30 * kHeight));
        
    }];
    self.detailButton.layer.cornerRadius = 5;
    self.detailButton.titleLabel.font = Font(14);
    
    
    
    //在途信息
    self.giveButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.giveButton];
    [self.giveButton setTitle:@"在途信息" forState:UIControlStateNormal];
    self.giveButton.backgroundColor = YellowColor;
    [self.giveButton setTitleColor:WhiteColor forState:UIControlStateNormal];
    [self.giveButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.detailButton.mas_left).offset(-10);
        make.top.equalTo(weakSelf.detailButton);
        make.size.equalTo(weakSelf.detailButton);
        
    }];
    self.giveButton.layer.cornerRadius = 5;
    self.giveButton.titleLabel.font = Font(14);
    
    
    //指派司机
    self.assignButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.assignButton];
    [self.assignButton setTitle:@"指派司机" forState:UIControlStateNormal];
    self.assignButton.backgroundColor = YellowColor;
    [self.assignButton setTitleColor:WhiteColor forState:UIControlStateNormal];
    [self.assignButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.equalTo(weakSelf.giveButton);
        make.centerX.centerY.equalTo(weakSelf.giveButton);
        
    }];
    self.assignButton.layer.cornerRadius = 5;
    self.assignButton.titleLabel.font = Font(14);

}

-(void)setModel:(DriverModel *)model
{
    if (model != _model) {
        
//       //待派单
//        if ([model.status integerValue] == 5) {
//            self.giveButton.hidden = YES;
//        }
//        //执行中
//
//        if ([model.status integerValue] == 10 || [model.status integerValue] == 20) {
//            self.assignButton.hidden = YES;
//            
//            //状态
//            self.statusLabel.text = [self backString:model.statusText];
//        }
//        
//        //已完成
//
//        if ([model.status integerValue] == 30) {
//            self.assignButton.hidden = YES;
//        }
        
        //待派单
        if (_number == 0) {
            self.giveButton.hidden = YES;
        }
        //执行中
        
        if (_number == 1) {
            self.assignButton.hidden = YES;
            
            //状态
            self.statusLabel.text = [self backString:model.statusTest];
        }
        
        //已完成
        
        if (_number == 2) {
            self.assignButton.hidden = YES;
        }

        
        
        NSArray *arr = [model.orderTime componentsSeparatedByString:@" "];
        
        //时间
        self.timeLabel.text = [self backString:arr[0]];
      
        //起始地
        self.startAddressLabel.text = [NSString stringWithFormat:@"%@",[self backString:model.depaAddr]];
        //目的地
        self.endAddressLabel.text = [NSString stringWithFormat:@"%@",[self backString:model.destAddr]];
        //价格
//        self.moneyLabel.text = [NSString stringWithFormat:@"￥%.2f",[model.orderPrice floatValue]];
    }
}

-(NSString *)backString:(NSString *)string
{
    
    if ([string isEqual:[NSNull null]]) {
        return @"";
    } else {
        return string;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
